package com.chinanet.repository.manager;

import com.chinanet.entry.manager.File;
import com.chinanet.entry.manager.QFile;
import com.querydsl.core.types.dsl.StringPath;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.data.querydsl.binding.QuerydslBinderCustomizer;
import org.springframework.data.querydsl.binding.QuerydslBindings;
import org.springframework.data.repository.PagingAndSortingRepository;

public interface FileRepository extends PagingAndSortingRepository<File,Long>, QuerydslBinderCustomizer<QFile>, QuerydslPredicateExecutor<File> {
    File findFirstByOrderByIdDesc();
    // 过滤
    default void customize(QuerydslBindings bindings, QFile file) {
/*        bindings.bind(relation.name).first((path, value) -> path.contains(value));
        bindings.bind(relation.name).first((path, value) -> path.containsIgnoreCase(value));*/
        bindings.bind(String.class).first((StringPath path, String value) -> {
            return  path.contains(value);
        });
    }
}